<template>
  <div class="lottery-add views-container">
    <el-dialog width="45%" :visible.sync="dialogListVisible" @close="clearData" custom-class="reset-pwd wlm-form-dialog dialog-table" style="margin-top: -10vh;">
      <div class="wlm-form" v-if="dialogListVisible" style="margin-bottom:0">
        <div class="wlm-form-header wlm-dialog-fixheader">
          <span class="wlm-dialog-inlenr">{{formType=='1'?'商家列表':'门店列表'}}</span>
        </div>
        <!-- <el-scrollbar wrap-class="scrollbar-wrapper"> -->
        <div class="wlm-table-header" style="margin-bottom:-20px;margin-top:14px;">
          <el-form :model="tableFormatData.userTable.files" size="small" label-width="110px" class="retail-form" label-position="right">
            <el-form-item label="" class="filter" label-width="10px">
              <el-form-item class="search">
                <el-input v-model="tableFormatData.userTable.files.name" placeholder="请输入名称" style="width:200px;margin-left:25px;"></el-input>
                <el-button style="margin-left:10px;" type="primary" @click="filesSerch">搜索</el-button>
              </el-form-item>
            </el-form-item>
          </el-form>
        </div>
        <el-table :row-class-name="tableRowClassName" v-loading="!isTableFormatGetEnd" v-if="formType=='1'" class="chooseTable" :data="tableFormatData.userTable.tableData" :row-style="{cursor:'pointer'}" @row-click="merchantRowClick" highlight-current-row style="width: 100%;padding:0 30px;border-bottom:none">
          <el-table-column prop="date" label="商家名称">
            <template slot-scope="scope">
              <p>{{scope.row.name}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="门店数量">
            <template slot-scope="scope">
              <p>{{scope.row.storenum}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="成为时间">
            <template slot-scope="scope">
              <p>{{scope.row.create_time}}</p>
            </template>
          </el-table-column>
        </el-table>
        <el-table ref="multipleTable" v-loading="!isTableFormatGetEnd" v-if="formType=='2'" class="chooseTable" @selection-change="storeChange" :data="tableFormatData.userTable.tableData" @row-click="storeRowClick" style="width: 100%;padding:0 30px;border-bottom:none">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column prop="date" label="门店名称">
            <template slot-scope="scope">
              <p>{{scope.row.name}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="店员数量">
            <template slot-scope="scope">
              <p>{{scope.row.menum}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="成为时间">
            <template slot-scope="scope">
              <p>{{scope.row.create_time*1000 | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</p>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-content flex-row flex-justify-e flex-align-c" style="padding-right: 20px;height:60px;">
          <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
          </el-pagination>
        </div>
        <!-- </el-scrollbar> -->
      </div>
      <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
        <el-button size="small" type="primary" @click="dialogListVisible = false">确定</el-button>
      </footer>
    </el-dialog>
    <!-- <el-dialog :visible.sync="dialogVisibleSource" width="60%" @selection-change="timestoreChange" custom-class="reset-pwd wlm-form-dialog dialog-table"> -->
            <!-- <div class="wlm-form" v-if="dialogVisibleSource">
                <div class="wlm-form-header wlm-dialog-fixheader">
                  <span class="wlm-dialog-inlenr">选择期数时间</span>
                </div>
                  <div style="display:flex;justify-content:space-between;padding:30px;">
                    <div>
                      快速设置
                    </div>
                    <div>
                      <el-date-picker
                          type="datetime"
                          v-model="periodtime"
                          placeholder="选择日期时间">
                        </el-date-picker>
                    </div>
                    <div>
                      <el-input-number v-model="days"  placeholder="请输入天数" style="width:200px;margin-left:25px;" :controls="false"></el-input-number>
                    </div>
                    <div>
                      <el-button @click="numberbtn">确定</el-button>
                    </div>
                  </div>

                <el-table ref="multipleTable" class="chooseTable" :data="tableFormatData.userTable.numtableData"  style="width: 100%;padding:0 30px;border-bottom:none">
                  <el-table-column prop="date" label="期数">
                    <template slot-scope="scope">
                        {{scope.row}}
                    </template>
                  </el-table-column>
                  <el-table-column prop="date" label="状态">
                    <template slot-scope="scope">

                    </template>
                  </el-table-column>
                  <el-table-column prop="date" label="活动开始时间">
                    <template slot-scope="scope">

                    </template>
                  </el-table-column>
                    <el-table-column prop="date" label="活动开奖时间">
                    <template slot-scope="scope">

                    </template>
                  </el-table-column>
                  <el-table-column prop="date" label="操作">
                    <template slot-scope="scope">
                      123123
                    </template>
                  </el-table-column>
                </el-table>

              </div> -->
       <!-- <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
        <el-button size="small" type="primary" @click="dialogListVisible = false">确定</el-button>
      </footer> -->
    <!-- </el-dialog> -->
    <div class="wlm-form">
      <div class="wlm-form-header">活动信息</div>
      <div class="wlm-form-content">
        <el-form ref="active" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="144px" class="retail-form" label-position="right">
          <el-form-item label="活动名称" prop="luck_title">
            <el-input :maxlength="50" v-model.trim="formFormatData.formData.luck_title">
            </el-input>
          </el-form-item>
          <el-form-item label="活动标签">
            <el-input v-model.trim="formFormatData.formData.luck_tag" >
            </el-input>
          </el-form-item>
          <el-form-item label="活动时间" prop="luck_time">
            <el-date-picker v-model="formFormatData.formData.luck_time" :disabled="$hasFormEdit" style="width:360px;"
            :default-time="[`${new Date().getHours()}:${(new Date().getMinutes() + 5).toString().padStart(2,'0')}:00`,'23:59:59']"
            :picker-options="afterOptions" value-format="timestamp" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
           <el-form-item label="活动开始预热时间"  prop="luck_start_begin_time">

<el-date-picker
     v-model="formFormatData.formData.luck_before_start_time"
      type="datetime"
        :picker-options="pickerTimes"
      placeholder="选择日期时间">
    </el-date-picker>
  <div class="form-help">活动预热时间不能晚于活动开始时间</div>

          </el-form-item>
          <el-form-item label="是否显示喜欢数量">
            <el-radio-group :disabled="$hasFormEnd" v-model="formFormatData.formData.luck_is_see">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="喜欢数量" prop="luck_like" v-if="formFormatData.formData.luck_is_see==1">
            <el-input v-model.trim="formFormatData.formData.luck_like" :disabled="$hasFormEnd">
            </el-input>
          </el-form-item>
          <el-form-item label="首页长方形风格展示图">
            <choose-files ref="chooseFiles" :config="chooseLogoConfig" :changeEvt="formFormatFiltersChange"></choose-files>
            <!-- <img style="border-radius: 6px;" v-if="$hasFormEdit&&formFormatData.formData.image && formFormatData.formData.image[0]" height="98" width="98" :src="formFormatData.formData.image[0]['file_path']" alt=""> -->
             <div class="form-help">建议尺寸700*400</div>
          </el-form-item>
          <el-form-item label="首页正方形风格展示图">
            <choose-files ref="chooseFiles" :config="chooselgConfig" :changeEvt="formFormatFiltersChange"></choose-files>
            <!-- <img style="border-radius: 6px;" v-if="$hasFormEdit&&formFormatData.formData.image_img && formFormatData.formData.image_img[0]" height="98" width="98" :src="formFormatData.formData.image_img[0]['file_path']" alt=""> -->
                <div class="form-help"> 建议尺寸750*750</div>
          </el-form-item>
          <el-form-item label="抽奖渠道" prop="luck_source">
            <el-checkbox-group v-model="formFormatData.formData.luck_source" >
              <el-checkbox label="2" v-if="JSON.stringify($store.getters.power).indexOf('wxapp')>-1">微信小程序</el-checkbox>
                  <el-checkbox label="3" v-if="JSON.stringify($store.getters.power).indexOf('H5')>-1">H5</el-checkbox>
                  <el-checkbox label="4" v-if="JSON.stringify($store.getters.power).indexOf('wechat')>-1">微信公众号</el-checkbox>
                  <el-checkbox label="7" v-if="JSON.stringify($store.getters.power).indexOf('aliapp')>-1">支付宝小程序</el-checkbox>
                  <el-checkbox label="9" v-if="JSON.stringify($store.getters.power).indexOf('toutiaoapp')>-1">抖音-头条</el-checkbox>
              <!-- <el-checkbox label="2" v-if="$store.getters.power.includes('wxapp')">微信小程序</el-checkbox>
              <el-checkbox label="3" v-if="$store.getters.power.includes('H5')">H5</el-checkbox>
              <el-checkbox label="4" v-if="$store.getters.power.includes('wechat')">微信公众号</el-checkbox>
              <el-checkbox label="7" v-if="$store.getters.power.includes('aliapp')">支付宝小程序</el-checkbox>
              <el-checkbox label="9" v-if="$store.getters.power.includes('toutiaoapp')">抖音-头条</el-checkbox> -->
            </el-checkbox-group>
            <div class="form-help">同时开通不同的抽奖渠道</div>
          </el-form-item>
          <el-form-item label="抽奖人群">
            <el-radio-group :disabled="$hasFormEdit" v-model="formFormatData.formData.luck_crowd">
              <el-radio :label="1">所有用户可参与</el-radio>
              <el-radio :label="2">仅会员可参与</el-radio>
              <el-radio :label="3">部分地区用户</el-radio>
              <el-radio :label="4">仅限分销商参与</el-radio>
              <el-radio :label="5" @change="luck_crowdbtn">标签用户</el-radio>
            </el-radio-group>
                <el-select multiple v-model="formFormatData.formData.luck_user_tag"  :disabled="$hasFormEdit" filterable placeholder="请选择" v-if="formFormatData.formData.luck_crowd=='5'">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
          </el-form-item>
          <el-form-item label="是否必须关注公众号" v-if="JSON.stringify($store.getters.power).indexOf('wechat')>-1">
            <el-radio-group  v-model="formFormatData.formData.is_subscribe" @change="changeRib">
              <el-radio :label="10">不需要</el-radio>
              <el-radio :label="20">需要</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="社群服务">
                  <!-- <el-select v-model="formFormatData.formData.community_type" placeholder="请选择客服类型" class="poster" @change="communitybtn">
                      <el-option :label="'社群'" :value="1">
                      </el-option>
                      <el-option :label="'客服'" :value="2">
                      </el-option>
                      <el-option :label="'公众号'" :value="3">
                      </el-option>
                      <el-option :label="'电话'" :value="4">
                      </el-option>
                  </el-select> -->
                   <el-select v-model="formFormatData.formData.community_id" placeholder="请选择" style="width:200px;"  >
                    <el-option v-for="(item,index) in selectValue" :key="index" :label="item.title" :value="item.id" ></el-option>
                  </el-select>
              </el-form-item>
          <el-form-item label="小程序关键字" v-if="formFormatData.formData.is_subscribe==20">
            <el-input v-model="formFormatData.formData.keyword">
            </el-input>
          </el-form-item>
          <el-form-item label="是否付费" >
            <el-radio-group :disabled="$hasFormEdit" v-model="formFormatData.formData.is_pay" @change="changeRib">
              <el-radio :label="1">付费抽奖</el-radio>
              <el-radio :label="2">非付费</el-radio>
            </el-radio-group>
          </el-form-item>
           <el-form-item label="是否退款"  v-if="formFormatData.formData.is_pay==1">
            <el-radio-group  v-model="formFormatData.formData.luck_pay_refund" @change="changeRib">
              <el-radio :label="1">未中奖用户退款</el-radio>
              <el-radio :label="2">不退款</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="付费金额" v-if="formFormatData.formData.is_pay==1">
            <!-- <el-input  v-model="formFormatData.formData.enjoy_money">
            </el-input> -->
             <el-input-number v-model="formFormatData.formData.enjoy_money"  :min="0.01" :controls="false"></el-input-number>
          </el-form-item>
          <el-form-item label="地区信息" v-if="formFormatData.formData.luck_crowd==3">
            <el-input  v-model.trim="formFormatData.formData.luck_city">
            </el-input>
            <p class="form-help">如果您希望仅限成都和重庆地区的用户参加抽奖，则填入成都、重庆，地区仅限市级地区</p>
          </el-form-item>
          <!-- <el-form-item label="社群开关">
                    <el-radio-group :disabled="$hasFormEdit" v-model="formFormatData.formData.luck_group">
                        <el-radio :label="1">开</el-radio>
                        <el-radio :label="2">关</el-radio>
                    </el-radio-group>
                    <div><span class="form-help">开通社群后，社群入口展示在抽奖详情页 </span>
                    </div>
                </el-form-item> -->

          <el-form-item label="是否支持裂变">
            <el-radio-group  v-model="formFormatData.formData.luck_fission">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
            </el-radio-group>
            <p class="form-help">可设置抽奖码玩法规则，开启之后邀请好友可额外获得抽奖码，需在抽奖规则中提醒加以说明 </p>
          </el-form-item>
          <el-form-item label="邀请可得抽奖码数" v-if="formFormatData.formData.luck_fission==1">
            <el-input-number  v-model="formFormatData.formData.luck_give_number" :controls="false" controls-position="right" :min="0"></el-input-number>
            <p class="form-help">非会员默认邀请一个好友可获得一个抽奖码 </p>
          </el-form-item>
          <el-form-item label="最多抽奖码个数">
            <el-input-number v-model="formFormatData.formData.luck_code_max" :controls="false" controls-position="right" :min="0" :max="20"></el-input-number>
            <p class="form-help">非会员默认可获得邀请码数量，最多只能20个 </p>
          </el-form-item>
           <el-form-item label="会员抽奖码特权">
              <el-switch v-model="formFormatData.formData.luck_vip_right"  :active-value="1" :inactive-value="2"></el-switch>
           </el-form-item>
            <el-form-item label="会员邀请可得抽奖码" v-if="formFormatData.formData.luck_vip_right==1">
              <el-input-number  v-model="formFormatData.formData.luck_vip_invite" :controls="false" controls-position="right" :min="0"></el-input-number>
            <p class="form-help">会员默认邀请一个好友可获得一个抽奖码 </p>
            </el-form-item>
            <el-form-item label="会员最多抽奖码个数" v-if="formFormatData.formData.luck_vip_right==1">
              <el-input-number  v-model="formFormatData.formData.luck_vip_invite_max" :controls="false" controls-position="right" :min="0"></el-input-number>
             <p class="form-help">会员默认可获得邀请码数量，无限制 </p>
            </el-form-item>
            <!-- <el-form-item label="自定义海报">
                <el-select v-model="formFormatData.formData.posterData" filterable placeholder="请选择">
                  <el-option
                    v-for="item in posteroptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
          </el-form-item> -->
          <el-form-item label="抽奖码有效期">
            <el-radio-group  v-model="formFormatData.formData.validity" class="wlm-form-group flex-col">
              <el-radio :label="10">生效时间起长期核销</el-radio>
              <el-radio :label="20">有效时间起
                <el-input style="width:60px;" v-model="formFormatData.formData.validity_day" placeholder=""></el-input>
                天内可使用
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="活动说明">
            <ueditor :ueditorChange="serverInfoChange" :ueditorList="ueditorList" :bindIndex="1" :defaultMsg='defaultMsg' :config='{initialFrameWidth: null,initialFrameHeight: 350}' ref="by_know"></ueditor>
          </el-form-item>
          <el-form-item label="活动规则">
              <el-input v-model="formFormatData.formData.luck_rule"  type="textarea" :rows="2" placeholder="请输入活动规则" style="width:60%;"></el-input>
          </el-form-item>
          <el-form-item label="自定义分享图片">
            <el-radio-group v-model="formFormatData.formData.activity_share" >
              <el-radio :label="10">默认分享卡</el-radio>
              <el-radio :label="20">自定义分享卡</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="分享图片" ref="businessbackgroundmap" v-if="formFormatData.formData.activity_share==20">
            <choose-files ref="chooseFiles" :config="chooseBgConfig" :changeEvt="formFormatFiltersChange"></choose-files>
            <div class="form-help">推荐尺寸：750X750，尺寸不匹配时，图片将选取部分展示</div>
          </el-form-item>
          <el-form-item label="">
            <div class="flex-col">
              <el-checkbox :true-label="20" :false-label="10" v-model="formFormatData.formData.is_custom">自定义分享文案</el-checkbox>
              <el-input v-if="formFormatData.formData.is_custom==20" placeholder="请输入分享文案"  v-model="formFormatData.formData.custom_share_content" style="width:80%;">
              </el-input>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="wlm-form">
      <div class="wlm-form-header">奖品信息</div>
      <div class="wlm-form-content">
        <el-form ref="info" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
          <el-form-item label="是否开启抽奖期数" >
               <el-switch v-model="formFormatData.formData.luck_period_flag" :disabled="$hasFormEdit" :active-value="1" :inactive-value="2"></el-switch>
          </el-form-item>
          <el-form-item label="抽奖期数" v-if="formFormatData.formData.luck_period_flag==1">
              共<el-input-number style="width:80px;" class="luckbtn" :disabled="$hasFormEdit" v-model="formFormatData.formData.luck_periods" placeholder="" :controls="false" :min="1" :max="20"></el-input-number>期
               <p class="form-help">最多设置20期 </p>
              <div class="limitbtn">
                一个用户最多参与期数<el-input-number style="width:80px;" :disabled="$hasFormEdit" v-model="formFormatData.formData.luck_limit_user_join" placeholder="" :controls="false"></el-input-number>
                <span>
                  注：请勿超过抽奖总期数
                </span>
              </div>
          </el-form-item>
          <el-form-item label="开奖方式">
            <el-radio-group :disabled="$hasFormEdit" v-model="formFormatData.formData.luck_mode">
              <el-radio :label="1">按时间开奖</el-radio>
              <el-radio :label="2">按人数开奖</el-radio>
              <el-radio :label="3">手动开奖</el-radio>
            </el-radio-group>
          </el-form-item>
           <el-form-item label="开奖人数" v-show="formFormatData.formData.luck_mode==2 " prop="luck_begin_number">
            <el-input :disabled="$hasFormEdit" size="small" v-model="formFormatData.formData.luck_begin_number"></el-input>
               <div class="form-help">注：每期开奖人数为一致</div>
          </el-form-item>
          <el-form-item label="首页开奖描述" v-if="formFormatData.formData.luck_mode==3">
                 <el-input v-model="formFormatData.formData.hand_text" :disabled="$hasFormEdit"></el-input>
                  <p class="form-help">不超过15个字 </p>
          </el-form-item>
          <el-form-item label="开奖时间" v-if="formFormatData.formData.luck_mode==1 &&formFormatData.formData.luck_period_flag!=1">
            <el-date-picker :disabled="$hasFormEdit" value-format="timestamp" v-model="formFormatData.formData.luck_begin_time" type="datetime" placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="设置时间" v-if="formFormatData.formData.luck_period_flag==1" >
              <!-- <el-button type="primary" @click="timebtn">设置期数抽奖时间</el-button> -->
                  <div style="display:flex;padding:30px;">
                    <div>
                      快速设置
                    </div>
                    <div style="margin-left:20px;">
                      <el-date-picker
                          type="datetime"
                          :disabled="$hasFormEdit"
                          v-model="formFormatData.formData.periodtime"
                          :picker-options="pickerOptions"
                          placeholder="选择日期时间">
                        </el-date-picker>
                         <p class="form-help">第一期活动开始时间 </p>
                      <!-- <el-date-picker  :picker-options="pickerOptions" type="date" placeholder="请选择活动开始时间" value-format="timestamp"></el-date-picker> -->
                    </div>
                    <div>
                      <el-input-number v-model="formFormatData.formData.days" :disabled="$hasFormEdit"  placeholder="请输入天数" style="width:200px;margin-left:25px;" :controls="false" :min="1"></el-input-number>
                     <p class="form-help">期数间隔（天） </p>
                    </div>
                    <div style="margin-left:100px;">
                      <el-button @click="numberbtn" :disabled="$hasFormEdit">确定</el-button>
                    </div>
                  </div>

                <el-table ref="multipleTable" class="chooseTable" :data="formFormatData.formData.periods"  style="width: 100%;padding:0 30px;border-bottom:none">
                  <el-table-column prop="date" label="期数">
                    <template slot-scope="scope" >
                        第{{scope.row.luck_period_id? scope.row.luck_period_id:scope.row.peridos}}期
                    </template>
                  </el-table-column>
                  <el-table-column prop="date" label="状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.period_state==1">已开奖</span>
                        <span v-if="scope.row.period_state==2">抽奖中</span>
                        <span v-if="scope.row.period_state==3">未开奖</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="date" label="活动开始时间">
                    <template slot-scope="scope">
                        <el-date-picker
                          type="datetime"
                          v-model="scope.row.start_time"
                          :picker-options="pickerOptions"
                          :disabled="$hasFormEdit"
                          placeholder="选择日期时间">
                        </el-date-picker>
                    </template>
                  </el-table-column>
                    <el-table-column prop="date" label="活动开奖时间">
                    <template slot-scope="scope">
                         <el-date-picker
                          type="datetime"
                          v-model="scope.row.lottery_time"
                          :disabled="$hasFormEdit"
                          placeholder="选择日期时间">
                        </el-date-picker>
                    </template>
                  </el-table-column>
                  <el-table-column prop="date" label="操作">
                    <template slot-scope="scope">
                      <el-button  class="wlm-text" type="text" @click="deletetimeTable(scope)" :disabled="$hasFormEdit">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
          </el-form-item>
          <!-- <el-form-item label="开奖时间" v-if="formFormatData.formData.luck_mode==1">
            <el-date-picker :disabled="$hasFormEnd" value-format="timestamp" v-model="formFormatData.formData.luck_begin_time" type="datetime" placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item> -->
           <!-- <el-form-item label="开奖时间" v-if="formFormatData.formData.luck_mode==3">
            <el-date-picker :disabled="$hasFormEnd" value-format="timestamp" v-model="formFormatData.formData.luck_begin_time" type="datetime" placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item>
           <el-form-item label="开始时间" v-if="formFormatData.formData.luck_mode==2">
            <el-date-picker :disabled="$hasFormEnd" value-format="timestamp" v-model="formFormatData.formData.luck_begin_time" type="datetime" placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item> -->

          <el-form-item label="关联商品">
            <choose-goods ref="chooseGoods" :config="chooseGoodsConfig" :changeEvt="filtersChange"></choose-goods>
            <el-button   type="primary" @click="goodsToogle">添加商品</el-button>
            <div class="form-help">选择关联推荐商品，促进用户消费</div>
            <el-table v-if="formFormatData.formData.goods!=''" :data="formFormatData.formData.goods" style="width: 100%">
              <el-table-column prop="date" label="商品">
                <template slot-scope="scope">
                  <div class="flex-row">
                    <img class="logo" v-if="scope.row.goods.image && scope.row.goods.image" :src="scope.row.goods.image[0]['file_path']">
                    <div class="inner-text">
                      <p>{{scope.row.goods.goods_name}}</p>
                      <span>￥:{{scope.row.goods.goods_price}}</span>
                    </div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="date" label="库存">
                <template slot-scope="scope">
                  <p>{{scope.row.goods.stock_num}}</p>
                </template>
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <div class="operation-group">
                    <el-button  class="wlm-text" type="text" @click="deleteTable(scope)">删除</el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item label="奖品数量" prop="luck_count">
            <el-input  v-model="formFormatData.formData.luck_count">
              <template slot="append">份</template>
            </el-input>
          </el-form-item>
          <el-form-item label="奖品价值">
            <el-input v-model="formFormatData.formData.luck_price">
            </el-input>
          </el-form-item>
          <el-form-item label="优惠券">
            <el-button type="primary"  @click="couponToogle" style="display: block;margin: 12px 0;">添加优惠券</el-button>
            <p class="form-help">可以添加最多一个优惠券</p>
            <choose-coupon ref="chooseCoupon" :config="chooseCouponConfig" :changeEvt="filtersCouponChange"></choose-coupon>
            <el-table class="coupon-table" v-show="formFormatData.formData.coupon_id!=''" :data="coupon_name" style="width: 50%;margin-top:20px;">
              <el-table-column prop="date" label="优惠券名称">
                <template slot-scope="scope">
                  <p>{{$coupon_name}}</p>
                </template>
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <div class="operation-group">
                    <el-button class="wlm-text" type="text"  @click="toggleSelection">删除</el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <!-- 把选择奖品的组件放在表单外面可以解决删除图片后无法再添加图片，弊端就是用户没有选择图片在编辑的时候选择不上图片 -->
                <!-- <choose-files ref="chooseFiles" :config="chooseFilesImage" :changeEvt="uploadChange" style="display:none;"></choose-files> -->
          <el-form-item label="奖品设置">
               <el-radio-group v-model="formFormatData.formData.luck_goods_set" @change="goodssetbtn">
                <!-- <el-radio :label="1">选择商品</el-radio> -->
                <el-radio :label="2">手动添加</el-radio>
              </el-radio-group>
              <div class="form-help">奖品图片建议尺寸：100*100</div>
            <el-table :data="formFormatData.formData.prize" style="width: 100%" v-if="formFormatData.formData.luck_goods_set==2">
               <el-table-column prop="date" label="奖品图片">
                  <template slot-scope="scope" >
                                <img class="update-load"  v-if="!!scope['row']['cover']" :src="scope.row.cover&&scope.row.cover.length? scope.row.cover[0]['file_path'] :''" width="50" height="50" @click="uploadColumn(scope.$index)" />
                                <div v-else class="flex-row flex-align-c flex-justify-c update-load" @click="uploadColumn(scope.$index)">
                                  <i class="el-icon-plus avatar-uploader-icon"></i>
                                </div>
                                  <choose-files ref="chooseFiles" :config="chooseFilesImage" :changeEvt="uploadChange" style="display:none;"></choose-files>
                              </template>
              </el-table-column>
              <el-table-column prop="date" label="奖品名称" width="300px;">
                <template slot-scope="scope">
                  <el-input  :maxlength="30" v-model="scope.row.prize_title"></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="date" label="数量">
                <template slot-scope="scope">
                  <div class="nowtop">
                    <el-input-number v-model="scope.row.num" :controls="false" controls-position="right" :min="0" style="width:50px;"></el-input-number>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="date" label="价格">
                <template slot-scope="scope">
                  <div class="nowtop">
                    <el-input-number   v-model="scope.row.price" :controls="false" controls-position="right" :min="0"></el-input-number>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="date" label="关联商家">
                <template slot-scope="scope">
                  <el-button style="max-width:200px;"  plain @click="showDialogSet(scope.$index)">
                    <p style="white-space: normal;">{{scope.row.business_id?scope.row.business_name:'选择对应奖品商家'}}</p>
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column prop="name" label="操作门店 (不选择门店时,任何门店都可以核销)" width="310px;">
                <template slot-scope="scope">
                  <el-button style="max-width:220px" plain @click="showDialogSetDoor(scope.$index,scope.row.business_id)">
                    <p style="max-width:200px;white-space: normal;">
                      <span v-if="scope.row.store.length>0" v-for="(item, index) in scope.row.store" :key="index">{{item.name}} {{scope.row.store.length>1 && index != scope.row.store.length-1?'/':''}}</span>
                      <span v-if="scope.row.store.length==0">所有门店</span>
                      <!-- {{scope.row.store.length>0?scope.row.storestore_name.join(' / '):'所有门店'}} -->
                    </p>
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column prop="date" label="会员专属" width="100px;">
                <template slot-scope="scope">
                  <el-switch v-model="scope.row.is_vip"></el-switch>
                </template>
              </el-table-column>

              <el-table-column label="操作">
                <template slot-scope="scope">
                  <div class="operation-group">
                    <el-button  class="wlm-text" type="text" @click="deleteGiftTable(scope)">删除</el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <el-button  v-if="formFormatData.formData.luck_goods_set==2" style="margin-top:10px;" type="primary" @click="addGiftTable" >添加奖品</el-button>
            <choose-goods ref="chooseGoods" :config="setchooseGoodsConfig" :changeEvt="filtersChange"></choose-goods>
             <el-table :data="formFormatData.formData.prize" style="width: 100%" v-if="formFormatData.formData.luck_goods_set==1">
               <el-table-column prop="date" label="奖品图片">
                  <template slot-scope="scope" >
                                <img class="update-load"  v-if="!!scope['row']['cover']" :src="scope.row.cover&&scope.row.cover.length? scope.row.cover[0]['file_path'] :''" width="50" height="50" @click="uploadColumn(scope.$index)" />
                                <div v-else class="flex-row flex-align-c flex-justify-c update-load" @click="uploadColumn(scope.$index)">
                                  <i class="el-icon-plus avatar-uploader-icon"></i>
                                </div>

                              </template>
              </el-table-column>
              <el-table-column prop="date" label="奖品名称" width="300px;">
                <template slot-scope="scope">
                  <el-input :maxlength="30" v-model="scope.row.prize_title"></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="date" label="数量">
                <template slot-scope="scope">
                  <div class="nowtop">
                    <el-input-number v-model="scope.row.num" :controls="false" controls-position="right" :min="0" style="width:50px;"></el-input-number>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="date" label="价格">
                <template slot-scope="scope">
                  <div class="nowtop">
                    <el-input-number   v-model="scope.row.price" :controls="false" controls-position="right" :min="0"></el-input-number>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="date" label="关联商家">
                <template slot-scope="scope">
                  <el-button style="max-width:200px;"  plain @click="showDialogSet(scope.$index)">
                    <p style="white-space: normal;">{{scope.row.business_id?scope.row.business_name:'选择对应奖品商家'}}</p>
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column prop="name" label="操作门店 (不选择门店时,任何门店都可以核销)" width="310px;">
                <template slot-scope="scope">
                  <el-button style="max-width:220px"  plain @click="showDialogSetDoor(scope.$index,scope.row.business_id)">
                    <p style="max-width:200px;white-space: normal;">
                      <span v-if="scope.row.store.length>0" v-for="(item, index) in scope.row.store" :key="index">{{item.name}} {{scope.row.store.length>1 && index != scope.row.store.length-1?'/':''}}</span>
                      <span v-if="scope.row.store.length==0">所有门店</span>
                      <!-- {{scope.row.store.length>0?scope.row.storestore_name.join(' / '):'所有门店'}} -->
                    </p>
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column prop="date" label="会员专属" width="100px;">
                <template slot-scope="scope">
                  <el-switch v-model="scope.row.is_vip" :active-value="2" :inactive-value="0"></el-switch>
                </template>
              </el-table-column>

              <el-table-column label="操作">
                <template slot-scope="scope">
                  <div class="operation-group">
                    <el-button  class="wlm-text" type="text" @click="deleteGiftTable(scope)">删除</el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <el-button  v-if="formFormatData.formData.luck_goods_set==1" style="margin-top:10px;" type="primary" @click="goodsTog" >选择商品</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
      <el-button size="small" @click="saveForm" type="primary" :loading="loading">保存</el-button>
      <router-link tag="span" to="/application/lottery">
        <el-button size="small">返回</el-button>
      </router-link>
    </div>
  </div>
</template>

<script>
import ChooseGoods from '@/components/ChooseGoods/index'
import ChooseCoupon from '@/components/ChooseCoupon/index'
import ChooseFiles from '@/components/ChooseFiles/index'
import ueditor from '@/components/Ueditor/index'
import dayjs from 'dayjs'
import {
  luckAddEdit,
  luckDetail,
  getUserTag

} from '@/api/application'
import {
  businessIndex,
  shopIndex,
  getLuckPoster,
  servicesList
} from '@/api/merchant'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Form'), mixins.getters('Table')],
  name: 'LotteryAdd',
  components: {
    ChooseGoods,
    ChooseFiles,
    ChooseCoupon,
    ueditor
  },
  watch:{
      // 'formFormatData.formData.luck_periods':{
      //   handler(newval,oldval){
      //     console.log("55555555555555",newval,oldval)
      //     this.formFormatData.formData.luck_periods=newval
      //   }
      // }
  },
  created() {
    this.ueditorDisable = (this.isFormEdit && this.formFormatData.formData.luck_state !== 3)
    this.posterbtn()
    this.communitybtn()
    this.luck_crowdbtn()
    if(this.$route.query.luck_id){
      this.showInput=true;
    }
  },
  computed: {
    $coupon_name() {
      return this.formFormatData.formData.coupon_name
    },
    getPath() {
      return function(path) {
        return (path.includes('https://') || path.includes('http://')) ? `${path}` : require(`@/assets/custorm_style/${path}`)
      }
    },
    isLuck_begin_number() {
      return this.formFormatData.formData.luck_mode === 2
    },
    $hasFormEdit() { // （1;已开奖、2：抽奖中、3：未开奖）
      return this.isFormEdit && this.formFormatData.formData.luck_state !== 3
    },
    $hasFormEnd() {
      return this.isFormEdit && this.formFormatData.formData.luck_state === 1
    }
  },
  data() {

    var checkTime = (rule, value, callback) => {
      const { message } = rule
      const time = this.formFormatData.formData.luck_time
      if ((Array.isArray(time) && time.length === 0) || !Array.isArray(time)) {
        return callback(new Error(`${message}！~`))
      } else {
        callback()
      }
    }

    var checkNumber = (rule, value, callback) => {
      console.log(value)
      const { isNull, isNot, key, isCheck } = rule
      const luck_count = this.formFormatData.formData[`${key}`]
      if (!isCheck) {
        if (luck_count !== '') {
          const $luck_count = Number(luck_count)
          if (!isNaN($luck_count)) {
            if ($luck_count === 0) {
              return callback(new Error(`${isNot}！~`))
            } else {
              callback()
            }
          }
        } else {
          return callback(new Error(`${isNull}！~`))
        }
      } else {
        if (this[`${isCheck}`]) {
          if (luck_count !== '') {
            const $luck_count = Number(luck_count)
            if (!isNaN($luck_count)) {
              if ($luck_count === 0) {
                return callback(new Error(`${isNot}！~`))
              } else {
                callback()
              }
            }
          } else {
            return callback(new Error(`${isNull}！~`))
          }
        }
      }
    }

    return {
      pickerOptions: {
        disabledDate(time) {

          return time.getTime() < Date.now() - 8.64e7
        },

      },
      pickerTimes:{
         disabledDate(time) {
            return time.getTime() < Date.now() - 8.64e7

        },
      },
      showInput:false,
       peidosNum:0,
      options: [],
      posteroptions: [],
      loading: false,
      coupon_name: [{}],
      ueditorDisable: false,
      lastID: -1,
      luck: { luckTitle: '' },
      luck_title: '',
      $index: -1,
      $lineIndex: -1,
      formType: '1',
      selectValue:[],
      dialogListVisible: false,
      dialogVisibleSource: false,
      ueditorList: [],
      currentRow: [],
      defaultMsg: '',
      // 图片
      chooseFilesImage: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          isMore: true,
          model: 'display'
        },
        // isUnique: true,
        initList: [],
        // isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'cover',
          model: 'img'
        }
      },
      chooseCouponConfig: {
        type: ['chooseCoupon'],
        model: 'display',
        get_limit_type: 0,
        disabled: [{
          label: 'status',
          value: 1,
          reverse: true
        },
        {
          label: 'get_limit_type',
          value: 1
        }, {
          label: 'coupon_type',
          value: 40
        }],
        initList: []
      },
      chooseGoodsConfig: {
        type: ['chooseGoods'],
        model: 'normal',
        unique: false,
        // disabled: [{
        //   label: 'sale_type',
        //   value: 0,
        //   reverse: true
        // }],
        initList: []
      },
      setchooseGoodsConfig: {
        type: ['chooseGoods'],
        model: 'normal',
        unique: false,
        // disabled: [{
        //   label: 'sale_type',
        //   value: 0,
        //   reverse: true
        // }],
        initList: []
      },
      chooseBgConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          isMore: true,
          model: 'display'
        },
        isUnique: true,
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'share_image_id',
          model: 'img'
        }
      },
      chooseLogoConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          isMore: true,
          model: 'display'
        },
        isUnique: true,
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'image',
          model: 'img'
        }
      },
      chooselgConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          isMore: true,
          model: 'display'
        },
        isUnique: true,
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'image_img',
          model: 'img'
        }
      },
      chooseData: [],
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: businessIndex
          },
          tableData: [],
          periods:[],
          files: {
            name: '',
            bus_id: '',
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      },
      formFormatData: {
        key: ['active', 'info'],
        model: {
          noCreateEdit: false,
          bindDialog: 'dialogListVisible'
        },
        api: {
          editForm: {
            api: luckDetail,
            params: {
              id: ''
            },
            filters: {
              choose: {
                bindInit: ['chooseGoodsConfig', 'setchooseGoodsConfig']
              },
              img: {
                bindInit: ['chooseLogoConfig', 'chooseBgConfig', 'chooselgConfig', 'chooseFilesImage']
              }
            },
            redirect: 'luck_id'
          },
          // submitForm: luckAddEdit
        },
        formData: {
          periods:[],
          luck_user_tag: [], // 标签
          posterData: '', // 海报
           luck_before_start_time:'',//预热时间
          periodtime:'',//期数日期
          kaiperiodtime:'',
          days:'',//天数
          cover: [],
          luck_tag: '',
          luck_title: '',
          luck_city: '',
          luck_state: '',
          luck_time: [],
          luck_like: '',
          luck_is_see: 2,
          luck_pay_refund:1,
          image: [],
          hand_text:'手动开奖',
          luck_source: [],
          luck_group: 1,
          luck_fission: 1,
          luck_give_number: '1',
          luck_begin_number: '',
          luck_goods_set: 2,
          luck_period_flag: 2,
          luck_periods: '',
          luck_limit_user_join: '',
          luck_code_max: '5',
          luck_vip_right: '2',
          luck_vip_invite: '',
          luck_vip_invite_max: '',
          luck_explain: '',
          luck_begin_time: '',
          is_subscribe: 10,
          community_type:'',
          community_id:'',
          is_pay: 2,
          enjoy_money: 0.01,
          keyword: '',
          luck_mode: 1,
          luck_count: '',
          luck_price: '',
          limit_num: '',
          goods: [],
          luck_crowd: 1,
          prize: [],
          coupon_id: '',
          validity_day: '',
          luck_rule: '',
          validity: 10,
          coupon_name: '',
          activity_share: 10,
          share_image_id: [],
          is_custom: 10,
          image_img: [],
          custom_share_content: ''
        },
        rules: {
          luck_title: [{
            message: '请填写活动名称',
            required: true,
            trigger: 'change'
          }],
          luck_like: [{
            message: '请填写喜欢数量',
            required: true,
            trigger: 'change'
          }],
          luck_source: [{
            message: '请填写活动渠道',
            required: true,
            trigger: 'change'
          }],
          luck_time: [{
            message: '请选择活动时间',
            required: true,
            validator: checkTime,
            trigger: 'change'
          }],

          luck_count: [{
            message: '请填写奖品数量',
            validator: checkNumber,
            key: 'luck_count',
            isNull: '请填写奖品数量',
            isNot: '奖品数量不能为0',
            required: true,
            trigger: 'change'
          }],
          luck_begin_number: [{
            validator: checkNumber,
            key: 'luck_begin_number',
            isCheck: 'isLuck_begin_number',
            isNull: '请填写开奖人数',
            isNot: '开奖人数不能为0',
            required: true,
            trigger: ['blur', 'change']
          }]
          // goods: [{
          //   message: '请选择活动商品',
          //   required: true,
          //   validator: checkGoods,
          //   trigger: 'change'
          // }]
        }
      }
    }
  },
  mounted(){
console.log("xxxxxxxxxxxx")


//  this.formFormatData.formData.luck_user_tag.map(item=>{
//    item=parseInt(item)
//  })
//  console.log(this.formFormatData.formData.luck_user_tag)
  },
  methods: {
    communitybtn(val){
      servicesList({list_rows: 'all' }).then(res=>{
        this.selectValue = res.data.data
      })
    },
    numberbtn(){
      // 循环期数，必须小于抽奖期数
      // formFormatData.formData.periodtime
        let mydata= this.formFormatData.formData.periods
       this.formFormatData.formData.periods = []//数据置空
      for(var num =1;num<=this.formFormatData.formData.luck_periods;num++){
        this.formFormatData.formData.periods.push({peridos:num})
      }
       let period_time=this.formFormatData.formData.periodtime;
       let period_days=this.formFormatData.formData.days;
       console.log(period_time);
   period_time = new Date(period_time).getTime();
    console.log()
   this.formFormatData.formData.periods.map((item,index)=>{

        // item.periods_start_time=period_time;
       const periodtime= dayjs(period_time).add(period_days, 'day').valueOf();
      //  let add_period_time={kaiperiodtime:periodtime};
      // item.kaiperiodtime=periodtime;
      console.log(period_time)
      console.log(periodtime)
      if(this.$route.query.luck_id){
        this.$set( this.formFormatData.formData.periods,index,{start_time:period_time,lottery_time:periodtime,peridos:index+1,luck_period_id:mydata[index].luck_period_id})
      }else{
         this.$set( this.formFormatData.formData.periods,index,{start_time:period_time,lottery_time:periodtime,peridos:index+1})
      }
    console.log( this.formFormatData.formData.periods)
        period_time=periodtime;

  })

      // 使用dayjs库，输入天数之后，自动计算
    //  const periodtime= dayjs(this.formFormatData.formData.periodtime).add(this.formFormatData.formData.days, 'day').valueOf()
        // this.formFormatData.formData.kaiperiodtime =periodtime
        // console.log(periodtime, this.tableFormatData.userTable.numtableData)

    },
      deletetimeTable(scope) {
       this.formFormatData.formData.periods.splice(scope.$index, 1)
    },
    // timebtn() {
    //   this.dialogVisibleSource = true
    // },
    // 自定义海报请求接口
    posterbtn() {
      getLuckPoster().then(res => {
        const { data: { data: msgData = [] } } = res
        this.posteroptions = msgData

      })
    },
    // 点击标签用户请求接口
    luck_crowdbtn() {
      getUserTag().then(res => {
        const { data: { data: msgData = [] } } = res

         msgData.map(item=>{
          item.value=item.value.toString()
        })
        this.options = msgData
        console.log(this.options)

      })
    },
    // 点击图片出现弹窗
    uploadChange({ displayData = [] }) {
      //  const {cover=''} = {}
      console.log("恢复单身复合大师接口放",displayData)
      this.formFormatData.formData.prize[this.$index].cover = displayData
      // this.$set(this.formFormatData.formData.cover[this.$index],'cover',cover)
      console.log("++++++++++++++++++++", this.formFormatData.formData.prize[this.$index].cover)
      // console.log("--------------------------------", displayData)
    },
    uploadColumn(index) {
      this.$refs.chooseFiles.toggle()
      this.$index = index
    },
    changeRib(val) {
      if (val === 20 && !this.formFormatData.formData.luck_source.includes('4')) {
        this.formFormatData.formData.luck_source.push('4')
      }
    },
    inputchange(value) {
      if (isNaN(Number(value))) {
        this.luck_title = ''
        console.log(this.luck_title)
      } else {
        console.log(this.luck_title)
      }
    },
    // clearReg(params, key, min = -1, max = -1, reg = /[^\d]/g) {
    //   this.$nextTick(() => {
    //     if (params[key] !== null) {
    //       params[key] = params[key].replace(reg, '')
    //       if (max !== -1 && params[key] > max) {
    //         params[key] = max
    //       }
    //       if (min !== -1 && params[key] < min) {
    //         params[key] = min
    //       }
    //     }
    //   })
    // },
    clearData() {
      this.lastID = -1
      console.log('ff')
    },
    merchantRowClick(row) {
      console.log(row)
      if (this.lastID !== row.id) {
        console.log('1')
        this.lastID = row.id
        if (row.storenum === 0) {
          console.log('22')
          this.$message({
            message: '该商家没有门店~',
            type: 'warning'
          })
        } else {
          const tableItem = this.formFormatData.formData.prize[this.$lineIndex]
          tableItem['business_id'] = row.id
          tableItem['business_name'] = row.name
          tableItem['store'] = []
          this.formFormatData.formData.prize.splice(this.$lineIndex, 1, tableItem)
        }
      }
    },
    storeChange(val) {
      // console.log('++++++++++++++++++++++++',val)
      console.log(this.$lineIndex, 'this.$lineIndex')
      this.formFormatData.formData.prize[this.$lineIndex]['store'] = []
      val.map(item => {
        this.formFormatData.formData.prize[this.$lineIndex]['store'].push({ id: item.id, name: item.name })
      })
    },
    timestoreChange(val){
           console.log('++++++++++++++++++++++++',val)
    },
    storeRowClick(row) {
      // console.log(row)
      // const tableItem = this.formFormatData.formData.prize[this.$lineIndex]
      // tableItem['store'] = row.id
      // tableItem['store_name'] = row.name
      // this.formFormatData.formData.prize.splice(this.$lineIndex, 1, tableItem)
    },
    serverInfoChange(msg) {
      this.defaultMsg = msg
    },
    formFormatCallBack(data, type, response) {
      if (type === 'editForm') {
        const { luck_explain } = data
        this.defaultMsg = luck_explain
        console.log('setDisabled', this.isFormEdit, this.formFormatData.formData.luck_state !== 3)
        if (this.isFormEdit && this.formFormatData.formData.luck_state === 1) {
          this.$refs.by_know.setDisabled()
        }
      }
    },
    saveForm() {
      // 保存到你要的那个form值里面
      // console.log("发多岁接口返回",this.formFormatData.formData.prize[this.$index].cover)
      if (this.formFormatData.formData.prize.length > 0) {
        this.formFormatData.formData.luck_explain = this.defaultMsg;
        // this.formFormatData.formData.periods=this.tableFormatData.userTable.periods;
          this.formFormatData.formData.prize.map(item=>{
            if(item.is_vip){item.is_vip=1}else{item.is_vip=0}
          })
          console.log("xxxxxxxxxxxxxxxxxxxxxxx")
          //console.log(this.formFormatData.formData.periods)
          // console.log(this.formFormatData.formData.periods)
          /console.log(this.formFormatData.formData.prize)
          this.formFormatData.formData.periods.map(item=>{
            if(typeof(item.start_time) != 'number' ){
              // console.log("111")
                item.start_time=new Date(item.start_time).getTime();
            }
            if(typeof(item.lottery_time) != 'number'){
             // console.log("111")
              item.lottery_time=new Date(item.lottery_time).getTime();
            }

          })
             if(typeof(this.formFormatData.formData.luck_before_start_time)!= 'number'){
               this.formFormatData.formData.luck_before_start_time=new Date(this.formFormatData.formData.luck_before_start_time).getTime();
             }

          if(!this.$route.query.luck_id){
             this.formFormatData.formData.periods.map(item=>{
               item.luck_id=0;
             })
          }
          console.log(this.formFormatData.formData.luck_periods,'1111111111111111')
          // if(this.luck_period_flag!=1){
          //   this.formFormatData.formData.luck_periods=1
          // }

      //  this.formFormatSubmit({ router: { type: 'replace', path: '/application/lottery', code: 1 } })
        const data = Base64.encode(JSON.stringify(this.formFormatData.formData))
        this.loading = true
        luckAddEdit({data}).then(res=>{
          this.loading = false
            const { data: { code, msg } } = res
          this.$message[code ? 'success' : 'error'](msg)
           code && this.$router.push('/application/lottery')
        }).finally(()=>{
          this.loading = false
        })
      } else {
        this.$message({
          message: '请添加奖品',
          type: 'warning'
        })
      }
     //  console.log( this.formFormatData.formData)
    },
    filtersChange(val) {
      console.log("分段函数看风景和第三款分段函数",val)
      this.currentRow = val.currentRow
      const displayData = val.displayData
      const result = []
      displayData.map(item => {
        const newData = { image: [{ file_path: item.image[0]['file_path'] }], goods_name: item.goods_name, goods_id: item.goods_id, stock_num: item.stock, goods_price: item.goods_min_price }
        result.push({ goods: newData, goods_id: item.goods_id })
      })
      this.formFormatData.formData.goods = result
      // this.formFormatData.formData.prize = displayData
    },

    goodsToogle() {
      const result = []
      this.formFormatData.formData.goods.map(item => {
        console.log('66666666666666666ddddddddddddddd', item)
        result.push(item.goods_id)
      })

      this.$refs.chooseGoods.toggle()
      // console.log("+++++++++++++++++",this.$refs.chooseGoods.displayData)
    },
    // 点击切换置空列表数据
    goodssetbtn() {
      if (this.formFormatData.formData.luck_goods_set == 1) {
        this.formFormatData.formData.prize = []
      }
      if (this.formFormatData.formData.luck_goods_set == 2) {
        this.formFormatData.formData.prize = []
      }
    },
    // 奖品设置选择商品
    goodsTog() {
      // if(this.formFormatData.formData.luck_goods_set==1){
      //   const result = []
      //   this.formFormatData.formData.prize.map(item =>{
      //       console.log("itesssssssssssssssssssssssss",item)
      //   })
      // this.$refs.chooseGoods.currentRow = result
      //     this.$refs.chooseGoods.toggle()
      // }
      this.$refs.chooseGoods.toggle()
    },
    deleteTable(scope) {
      this.formFormatData.formData.goods.splice(scope.$index, 1)
      this.currentRow.splice(scope.$index, 1)
    },
    deleteGiftTable(scope) {
      this.formFormatData.formData.prize.splice(scope.$index, 1)
    },

    addGiftTable() {
      this.formFormatData.formData.prize.push({ business_id: '', store: [], business_name: '', cover: '', num: '', price: '', is_vip: false })
    },
    showDialogSet(data) {
      this.$lineIndex = data
      this.formType = '1'
      this.tableFormatData.userTable.api.getList = businessIndex
      this.filesSerch()
      this.dialogListVisible = true
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.storenum === 0) {
        return 'disable-row'
      }
      return ''
    },
    filtersCouponChange(arg) {
      const { displayData } = arg
      const dislength = displayData.length - 1
      displayData.map(item => {
        this.formFormatData.formData.coupon_id = displayData[dislength]['coupon_id']
        this.formFormatData.formData.coupon_name = displayData[dislength]['name']
      })
      // this.formFormatData.formData.coupon_name = displayData.map(item=>{item.id})
    },
    couponToogle() {
      this.$refs.chooseCoupon.toggle()
    },
    toggleSelection() {
      this.formFormatData.formData.coupon_id = ''
    },
    showDialogSetDoor(data, bus_id) {
      this.$lineIndex = data
      this.formType = '2'
      this.tableFormatData.userTable.files.bus_id = bus_id
      this.tableFormatData.userTable.api.getList = shopIndex
      this.filesSerch()
      this.dialogListVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
$update: 50px;
.lottery-add {
  .logo {
    height: 40px;
    width: 40px;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 6px;
  }
  .nowtop{
    /deep/ .el-input__inner{
      width: 80px;
    }
  }
  /deep/ .chooseTable .el-table__body tr.current-row > td {
    background: #66b1ff !important;
    color: #fff;
  }

  /deep/ .el-table__body tr:hover > td {
    background-color: transparent !important;
  }
  .update-load {
    display: inline-block;
    cursor: pointer;
    width: $update;
    height: $update;
    background: #fafbff;
    border: 1px dashed #c0ccda;
    color: #a8abb0;
    border-radius: 5px;

    i {
      font-size: 14px;
      color: #8c939d;
      width: $update;
      height: $update;
      line-height: $update;
      text-align: center;
    }
    .el-select-dropdown{
      max-width: 243px;
    }
    .el-select-dropdown__item{
      display:inline-block;
    }
    .el-select-dropdown__item span{
      min-width: 205px;
      display: inline-block;
    }
  }
  /deep/ .el-table .disable-row {
    background: #c8c9cc !important;
    color: #999;
  }
  .limitbtn{
    /deep/ .el-input__inner{
      width: 80px;
    }
  }
  .luckbtn{
    /deep/ .el-input__inner{
      width: 80px;
    }
  }
}
</style>
